<?php

/**
 * Description of User_Info
 *
 * @author fabrice
 */
class Model_User_Info extends PDO_Mysql {

    protected $_name = 'user_info';
    protected $_primary = 'id_user';

    /**
     * Recupere tout les utilisateurs
     * @return <array>
     */
    public function getUserInfoById($id_user, $column = NULL) {

        if ($column == NULL) {
            $sql = 'SELECT * FROM ' . $this->_name . " WHERE id_user=" . $id_user;
            $result = $this->pquery($sql);

            $row = $this->pfetchAll($result);
        } else {
            $sql = "SELECT $column FROM " . $this->_name . " WHERE id_user=" . $id_user;
            $result = $this->pquery($sql);

            $row = $this->pfetch($result);
//            $row
        }

        return $row;
    }

    /**
     * Insert dans la BDD
     * @param <array> $formData
     * @return <int> $row
     */
    public function setUserInfo($formData) {

        $sql = 'INSERT INTO ' . $this->_name . ' (id_user,date_naissance,ville,origine)' .
                ' VALUES (:id_user,:date_naissance,:ville,:origine)';
        $data = array(
            ':id_user' => $formData['id_user'],
            ':date_naissance' => $formData['date_naissance'],
            ':ville' => $formData['ville'],
            ':origine' => $formData['origine']
        );
        $row = $this->pinsert($sql, $data);
        return $row;
    }

}

?>